package Interfazeak;
/**
 * 
 * @author Txantxangorriak
 *
 */
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import Futbol_Liga.Jokalaria;
import Futbol_Liga.Merkatua;
import Futbol_Liga.TaldeZerrenda;
import Futbol_Liga.Taldea;

public class EI_JokalariaSaldu extends JFrame {

	private JPanel contentPane;
	private JButton btnOnartu;
	private JComboBox<String> comboBox;
	private JComboBox<String> comboBox_1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					EI_JokalariaSaldu frame = new EI_JokalariaSaldu();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public EI_JokalariaSaldu() {
		setTitle("Jokalaria Saldu");
		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBackground(Color.BLUE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblZeinJokalariSaldu = new JLabel("Zein Jokalari Saldu Nahi Duzu???");
		lblZeinJokalariSaldu.setForeground(Color.WHITE);
		lblZeinJokalariSaldu.setFont(new Font("Times New Roman", Font.BOLD, 15));
		lblZeinJokalariSaldu.setBounds(44, 57, 345, 14);
		contentPane.add(lblZeinJokalariSaldu);
		
		
		
		JLabel lblTaldea = new JLabel("TALDEA");
		lblTaldea.setForeground(Color.WHITE);
		lblTaldea.setFont(new Font("Times New Roman", Font.BOLD, 15));
		lblTaldea.setBounds(28, 108, 72, 14);
		contentPane.add(lblTaldea);
		
		JLabel lblJokalaria = new JLabel("JOKALARIA");
		lblJokalaria.setForeground(Color.WHITE);
		lblJokalaria.setFont(new Font("Times New Roman", Font.BOLD, 15));
		lblJokalaria.setBounds(28, 169, 107, 14);
		contentPane.add(lblJokalaria);
		
		comboBox = new JComboBox<String>();
		comboBox.setBounds(144, 103, 204, 24);
		final TaldeZerrenda tz=TaldeZerrenda.getTaldeZerrenda();
		Iterator<Taldea> it=tz.getIteratzailea();
		while(it.hasNext()){
			comboBox.addItem(it.next().getIzena());
		}
		contentPane.add(comboBox);
		
		
		
		btnOnartu = new JButton("ONARTU");
		btnOnartu.setBounds(316, 212, 107, 23);
		btnOnartu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				Taldea tal=tz.getTaldea(comboBox.getSelectedItem().toString());
		
				comboBox.setVisible(false);
				
				comboBox_1 = new JComboBox<String>();
				comboBox_1.setBounds(144, 164, 204, 24);
				Iterator<Jokalaria> it2=tal.getJokalariak().getIteratzailea();
				while(it2.hasNext()){
					comboBox_1.addItem(it2.next().getIzena());
				}
				contentPane.add(comboBox_1);
				
				btnOnartu.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent arg0) {
	                    	Merkatua mer=Merkatua.getMerkatua();
	                    	mer.saldu(comboBox.getSelectedItem().toString(), comboBox_1.getSelectedItem().toString());
	                    	  EI_MENUA fl= new EI_MENUA();
	          				fl.setVisible(true);
	          				EI_JokalariaSaldu.this.setVisible(false);
	                  
		
			 
		}});
  }});

		
			
				
		
		contentPane.add(btnOnartu);
		
		System.out.println("SALDUTA");
		
		
	}
}
